package com.example.test_activity.utils;


import com.example.test_activity.entity.Information;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学籍信息
 * Created by 旭 on 2017/3/17/017.
 */

public class GetInformation {

    private List<Map<String,String>> list = new ArrayList<>();

    public List<Map<String,String>> getInformation(String html)
    {
        Document document = Jsoup.parse(html);

        Elements elements = document.select("[id=tblView]");
        if (elements.isEmpty())
        {
            return list;
        }
        Element element = elements.get(0);

        Elements ele = element.getAllElements();
        for (int i=0;i<ele.size();++i)
        {
            Element e = ele.get(i);
            Information information = new Information();

            if (e.attr("width").equals("180"))
            {
                String info = e.text();
                information.setInfo(info);
                ++i;
            }
            Element e_2 = ele.get(i);
            if (e_2.attr("width").equals("275"))
            {
                String value = e_2.text();
                information.setValue(value);
            }
            if (information.getInfo() == null && information.getValue() == null)
            {
            }else
            {
                getData(information);
            }
        }
        return list;
    }

    private void getData(Information information)
    {
        Map<String,String> map = new HashMap<>();
        map.put("info",information.getInfo());
        map.put("value",information.getValue());
        list.add(map);
    }
}
